(:
  A procedure to select the contents of the "chat" interventions
:)
declare boundary-space strip;
import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;
declare namespace gml = "http://graphml.graphdrawing.org/xmlns";
<display>{
let $t := $arguments[1] 
let $doc := doc($t)
let $d := $doc/gml:graphml/gml:graph/gml:node[gml:data[@key="object"]="note"]
for $e at $p in $d
let $Lstring := xs:string($e/gml:data[@key="createdAsLong"])
let $ts := xs:integer(fn:substring($Lstring,1,fn:string-length($Lstring)-1))
where $p < 1000
order by $ts
return
  <item>{
    <info name="time"><time><date>{$ts}</date><duration>0</duration></time></info>,
    <info name="src-anchor">{
      <anchor>{
        <doc>{ $t }</doc>,
        <path>//node[@id={xs:string($e/@id)}]</path>
      }</anchor>
    }</info>,
    for $data in $e/gml:data
	where fn:empty($data[@key=("time","src-anchor","id","label","createdAsLong","node","view",
															"VL","VLWC","modified","words","newWords","newWordCount","reads","revs","activated","originalX", "originalY")]) and $data/text() != "null"
    return
        <info>{
  				attribute name {xs:string($data/@key)},
  				jj:remove-html($data/text())
  			}</info>,
  	<info name="id">{xs:string($e/@id)}</info>,
  	<info name="parent">{xs:string($doc/gml:graphml/gml:graph/gml:edge[gml:data[@key="relation"]="buildson"][@source=$e/@id]/@target)}</info>		
  }</item>
}</display>
